//
//  File.swift
//  Locman-Map
//
//  Created by 康凯 on 16/06/2017.
//  Copyright © 2017 康凯. All rights reserved.
//

import Foundation
import UIKit

extension UIView {
    
    // MARK:- 上下左右中
    var left: (CGFloat) {
        set {
            var frame = self.frame
            frame.origin.x = newValue
            self.frame = frame
        }
        
        get {
            return self.frame.origin.x
        }
    }
    
    var top: CGFloat {
        set {
            var frame = self.frame
            frame.origin.y = newValue
            self.frame = frame
        }
        
        get {
            return self.frame.origin.y
        }
    }
    
    var right: CGFloat {
        set {
            var frame = self.frame
            frame.origin.x = newValue - frame.width
            self.frame = frame
        }
        
        get {
            return self.frame.origin.x + self.frame.width
        }
    }
    
    var bottom: CGFloat {
        set {
            var frame = self.frame
            frame.origin.y = newValue - frame.height
            self.frame = frame
        }
        
        get {
            return self.frame.origin.y + self.frame.height
        }
    }
    
    var width: CGFloat {
        set {
            var frame = self.frame
            frame.size.width = newValue
            self.frame = frame
        }
        
        get {
            return self.frame.width
        }
    }

    var height: CGFloat {
        set {
            var frame = self.frame
            frame.size.height = newValue
            self.frame = frame
        }
        
        get {
            return self.frame.height
        }
    }
    
    var centerX: CGFloat {
        set {
            var center = self.center
            center.x = newValue
            self.center = center
        }
        
        get{
            return self.center.x
        }
    }
    
    var centerY:CGFloat {
        set {
            var center = self.center
            center.y = newValue
            self.center = center
        }
        
        get {
            return self.center.y
        }
    }

    // MARK:- 位置 大小
    var origin: CGPoint {
        set {
            var frame = self.frame
            frame.origin = newValue
            self.frame = frame
        }
        
        get {
            return self.frame.origin
        }
    }
    
    var size: CGSize {
        set {
            var frame = self.frame
            frame.size = newValue
            self.frame = frame
        }
        
        get {
            return self.frame.size
        }
    }
    
    // MARK:- 位移 缩放
    open func horizontalMove(_ moveValue: CGFloat) {
        self.centerX += moveValue
    }
    
    open func verticalMove(_ moveValue: CGFloat) {
        self.centerY += moveValue
    }
    
    open func widthAdd(_ addValue: CGFloat){
        self.width += addValue
    }
    
    open func heightAdd(_ addValue: CGFloat){
        self.height += addValue
    }
}
